
/**author:yebinx email:yebinx@21cm.com*/
export class TipManager{
    private static _ins:TipManager;
    private tip:Tip;
    constructor(){
        this.tip=new Tip();
    }

    public showTip(_x:number,_y:number,value:string,_parent:any=null){
        let tp = _parent?_parent:Laya.stage;
        this.tip.setdata(value);
        this.tip.pos(_x,_y);
        if(this.tip.x<0)this.tip.x=0;
        else if(this.tip.x>tp.width)this.tip.x=720-300;
        if(this.tip.y<0)this.tip.y=0;
        else if(this.tip.y>tp.height)this.tip.y=1280-this.tip.height;
        tp.addChild(this.tip);
    }

    public hideTip(){
        if(this.tip.parent)this.tip.parent.removeChild(this.tip);
    }

    public showMsgAlert(value:string,_parent:any=null,_x?:number,_y?:number,_time?:number,_size?:number){
        let tp = _parent;
        let tx:number=_x?_x:(Laya.stage.width-400)/2;
        let ty:number=_y?_y:Laya.stage.height/2+100;
        let time:number=_time?_time:2000;
        if(!tp)tp = Laya.stage
        let talert=Laya.Pool.getItemByClass("msgAlert",MsgAlert);
        talert.x=tx;
        talert.y=ty;
        if(_size)talert.txt.fontSize=_size;
        talert.setdata(value);
        tp.addChild(talert);
        Laya.Tween.clearTween(talert);
        Laya.Tween.to(talert,{y:ty-100},time,null,Laya.Handler.create(this,(_alert)=>{
            _alert.removeSelf();
            Laya.Pool.recover("msgAlert",_alert);
        },[talert]))
    }
	
	public showMsgAlert2(value:string,_parent:any=null,_x:number,_y:number){
		 let tp = _parent;
         if(!tp)tp = Laya.stage;
         let tx:number=_x?_x:Laya.stage.width/2;
         let ty:number=_y?_y:Laya.stage.height/2;
		  let talert=Laya.Pool.getItemByClass("msgAlert2",MsgAlert2);
		  talert.x=tx;
		  talert.y=ty;
		  talert.setdata(value);
		  tp.addChild(talert);
		  Laya.Tween.clearTween(talert);
		  Laya.Tween.to(talert,{y:ty-100},2000,null,Laya.Handler.create(this,(_alert)=>{
		      _alert.removeSelf();
		      Laya.Pool.recover("msgAlert2",_alert);
		  },[talert]))
	}


    public static get ins():TipManager{
        if(!this._ins)this._ins=new TipManager();
        return this._ins;
    }
}

export class Tip extends Laya.Sprite{
    private txt:Laya.Label;
    constructor(){
        super();
        this.txt=new Laya.Label();
        this.txt.width=300;
        this.txt.wordWrap=true;
        this.txt.color="#ffffff";
        this.txt.stroke=2;
        this.txt.strokeColor="#d5dd17";
        this.txt.fontSize=30;
        this.txt.y=6;
        this.addChild(this.txt);

    }

    public setdata(_vaue:string){
        this.txt.text=_vaue;
        this.graphics.drawRect(0,0,300,this.txt.textField.textHeight+12,0x0);
    }
}

export class MsgAlert extends Laya.Sprite{
    public txt:Laya.Label;
    constructor(){
        super();
        this.txt=new Laya.Label();
        this.txt.width=400;
        this.txt.height=100;
        this.txt.wordWrap=true;
        this.txt.color="#ffffff";
        this.txt.stroke=2;
        this.txt.strokeColor="#d5dd17";
        this.txt.fontSize=40;
        this.txt.align="center";
        this.addChild(this.txt);
    }

    public setdata(_vaue:string){
        this.txt.text=_vaue;
    }
}

export class MsgAlert2 extends Laya.Sprite{
    public txt:Laya.Label;
    constructor(){
        super();
        this.txt=new Laya.Label();
        // this.txt.width=400;
        // this.txt.height=100;
        // this.txt.wordWrap=true;
        this.txt.color="#ffffff";
        this.txt.stroke=2;
        this.txt.strokeColor="#d5dd17";
        this.txt.fontSize=40;
        //this.txt.align="center";
        this.addChild(this.txt);
    }

    public setdata(_vaue:string){
        this.txt.text=_vaue;
    }
}